<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-add" lay-event="add">流程执行过程</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-add" lay-event="his">历史批注</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-add" lay-event="chakan">查看当前流程图</a>
        </script>

    </div>
</div>

<div id="showViewAdd" style="display: none">
    <div  style="text-align: center;font-size: 20px;padding-top: 5px">流程执行过程</div>
    <div>
        <table class="layui-table">
            <colgroup>
<!--                <col width="150">-->
                <col width="150">
                <col width="150">
                <col width="150">
            </colgroup>
            <thead>
            <tr>
<!--                <th>任务节点ID</th>-->
                <th>任务节点名称</th>
                <th>开始时间</th>
                <th>结束时间</th>
            </tr>
            </thead>
            <tbody id="tbodyAdd">

            </tbody>

        </table>
    </div>
</div>

<div id="showViewHis" style="display: none">
    <div  style="text-align: center;font-size: 20px;padding-top: 5px">批注列表</div>
    <div>
        <table class="layui-table">
            <colgroup>
                <col width="150">
                <col width="200">
                <col width="200">
                <col width="100">
                <col width="200">
            </colgroup>
            <thead>
            <tr>
                <th>名称</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>审批人</th>
                <th>审批内容</th>
            </tr>
            </thead>
            <tbody id="tbodyHis">

            </tbody>

        </table>
    </div>
</div>


<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/common.js"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: webUrl+'/task/historyTask?userId='+window.localStorage.getItem("userId")+'&finished=2',
            toolbar: '#toolbarDemo',
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            skin: 'line',
            page:true,
            cols: [[
                {field:'zizeng',  title: '序号',width: 80,align:'center',templet:function (d) {
                        return d.LAY_TABLE_INDEX+1;
                    }},
                {field: 'id', width: 180, title: '任务ID',align:'center'},
                {field: 'name', width: 180, title: '环节',align:'center', sort: true},
                {field: 'createTime', width: 180, title: '开始时间',align:'center',templet:function (d) {
                        return showTime(d.createTime);
                    }},
                {field: 'endTime', width: 180, title: '结束时间',align:'center', sort: true,templet:function (d) {

                        return d.endTime==null?'':showTime(d.endTime);
                    }},
                {field: 'memberName', width: 180, title: '审批人',align:'center', sort: true},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: 'center'}
            ]],
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
        });

        //监听单元格事件
        table.on('tool(currentTableFilter)', function(obj){
            var data={
                'taskId':obj.data.id
            }
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 1,
                        title:'流程执行过程',
                        area: ['700px', '750px'], //自定义文本域宽高
                        content: $('#showViewAdd') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                    });
                    $.ajax({
                        type:"post",
                        dataType:"json",
                        url: webUrl+'/task/listAction',//url
                        contentType: "application/json; charset=utf-8",
                        data:JSON.stringify(data),
                        success: function (result) {
                            if (result.data.rows.length>0) {
                                var t=result.data.rows;
                                var tbody="";
                                for(var i in t){
                                    var tt=t[i];
                                    var endTime=tt.endTime==null?'':showTime(tt.endTime);

                                    tbody+='<tr><td>'+tt.activityType+'</td><td>'+
                                        showTime(tt.startTime)+'</td><td>'+endTime+'</td></tr>'
                                }
                                $("#tbodyAdd").html(tbody);

                            }
                        },
                        error: function () {
                            layer.msg("操作失败");
                        }

                    })
                    break;
                case 'his':
                    layer.open({
                        type: 1,
                        title:'查看历史批注',
                        area: ['700px', '750px'], //自定义文本域宽高
                        content: $('#showViewHis') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                    });
                    $.ajax({
                        type:"post",
                        dataType:"json",
                        url:  webUrl+'/task/commentList',//url
                        contentType: "application/json; charset=utf-8",
                        data:JSON.stringify({'processInstanceId':obj.data.processInstanceId}),
                        success: function (result) {
                            if (result.data.rows.length>0) {
                                var t=result.data.rows;
                                var tbody="";
                                for(var i in t){
                                    var tt=t[i];
                                    var endTime=tt.endTime==null?'':showTime(tt.endTime);

                                    tbody += '<tr><td>' + tt.name + '</td><td>' + showTime(tt.createTime) + '</td>'+
                                        '<td>' + endTime + '</td><td>' + tt.memberName +'</td><td>' + tt.comment +'</td></tr>';
                                }
                                $("#tbodyHis").html(tbody);

                            }
                        },
                        error: function () {
                            layer.msg("操作失败");
                        }

                    })
                    break;
                case 'chakan':
                    var index = layer.open({
                        title: '查看当前流程图',
                        type: 2,
                        area: ['1100px', '600px'],
                        content: '../../processDefinition/showViewByTaskId?taskId='+obj.data.id,
                    });
                    break;

            }

        });


    });
    //时间转换函数
    function showTime(tempDate)
    {
        var d = new Date(tempDate);
        var year = d.getFullYear();
        var month = d.getMonth();
        month++;
        var day = d.getDate();
        var hours = d.getHours();

        var minutes = d.getMinutes();
        var seconds = d.getSeconds();
        month = month<10 ? "0"+month:month;
        day = day<10 ? "0"+day:day;
        hours = hours<10 ? "0"+hours:hours;
        minutes = minutes<10 ? "0"+minutes:minutes;
        seconds = seconds<10 ? "0"+seconds:seconds;


        var time = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
        return time;
    }

</script>

</body>
</html>